﻿using System;

namespace EmbeddedSharp.Core.Function.Arithmetics {

    /// <summary>
    /// a = 1/2;
    /// echo(a);
    /// # result is 1.5
    /// </summary>
    public class DivNode : OperatorNode {
        public DivNode() {
            Value = "/";
            Precedence = 2;
        }

        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }

        public override FuncNode GetReversedFunction(int index) {
            return new MulNode();
        }

        public override object Evaluate() {
            object value = Left.Evaluate();
            double lr = Convert.ToDouble(value);

            value = Right.Evaluate();
            double rr = Convert.ToDouble(value);

            return (lr / rr).ToString();
        }
    }
}
